<!DOCTYPE html>
<html>
	<!--巡检项目详情的新模块代码-->
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>巡检项目详情</title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
		<link rel="stylesheet" href="../../script/ccssoft/css/ccssoft-lite.css" />
		<link rel="stylesheet" type="text/css" href="../../script/easydialog/easydialog.css" />
		<link rel="stylesheet" type="text/css" href="../../css/aui-flex.css" />
		<style>
			body {
				padding: 0px;
				margin: 0px;
			}
			.inputstyle {
				width: 50%;
				margin: 0px;
				padding: 0px 15px;
			}
			.input-txt {
				display: inline-block;
				position: absolute;
				left: 44%;
				top: 15px;
			}
			.header-nav {
				position: relative;
			}
			.transparent_class {
				filter: alpha(opacity=50);
				-moz-opacity: 0.5;
				-khtml-opacity: 0.5;
				opacity: 0.5;
			}
			.easyDialog_text ul li:nth-child(odd) {
				background: #ffffff;
				padding: 10px 0;
				font-size: 16px;
				border-radius: 5px;
				text-align: center;
			}
			.easyDialog_text ul li:nth-child(even) {
				background: #f3f5f6;
				padding: 10px 0;
				font-size: 16px;
				border-radius: 5px;
				text-align: center;
			}
			.q_login_logo {
				background: url("../../image/x.png");
				width: 20px;
				height: 20px;
				position: relative;
				float: right;
				right: 0px;
				top: 4px;
			}
		</style>
	</head>
	<body>
		<!--下拉列表-->
		<script id="dict-template" type="text/x-dot-template">
			{{ for(var i=0, len=it.length; i < len; i++) {}}
			<option value="{{=it[i].hiddencontent}}">{{=it[i].hiddencontent}}</option>
			{{ } }}
		</script>
		<script id="m-template" type="text/x-dot-template">
			{{ for(var i=0, len=it.length; i < len; i++) {}}
			<option value="{{=it[i].itemvalue}}">{{=it[i].itemname}}</option>
			{{ } }}
		</script>
		<!--新增资源-->
		<script id="m-addres" type="text/x-dot-template">
			<li class="aui-list-view-cell aui-switch-body">
			<div name="addname_name" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			{{=it.resource_type}}：
			</div>
			<input  name="res_devname"  type="number" value="{{=it.real_num}}" class="textareaborder" style="width:50%;margin: 0px;padding: 0px 15px" >
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
		</script>
		<div class="aui-content">
			<form>
				<ul id="list-view" class="aui-list-view"></ul>
			</form>
		</div>
		<div style="height:50px;"></div>
		<div id="downloadBtn" class="fixed_bottom" style="display: none;">
			<button class="outline center aui-btn aui-btn-success" onclick="downloadPic();">
				下载图片
			</button>
		</div>
		<!--门禁列表-->
		<script id="doorDevice-template" type="text/x-dot-template">
			{{ for(var i=0, len=it.length; i < len; i++) {}}
			<li onclick="getRes(this)" data-name="{{=it[i]}}" >{{=it[i]}}</li>
			{{ } }}
		</script>
		<div class="easyDialog_wrapper" id="easyDialogWrapper">
			<div class="easyDialog_content">
				<h4 class="easyDialog_title" id="easyDialogTitle" style="background-color: #db4537;color:#FFFFFF;">请选择资源类型<span onclick="closeDiv()" class="q_login_logo"></span></h4>
				<div class="easyDialog_text" style="padding:0;height: auto;overflow:auto;max-height: 300px;">
					<ul id="doorDeviceList"></ul>
				</div>
			</div>
		</div>
		<!--项目详情-->
		<script id="parol-template" type="text/html">
			<input type="hidden" name="action" value="2" />
			<input type="hidden" name="taskid" value="{{=it.takeid}}" />
			<!--<input type="hidden" name="unitname" value="{{=it.fillunit}}" />
			<input type="hidden" name="filltype" value="{{=it.filltype}}" />
			<input type="hidden" name="taskid" value="{{=it.taskid}}" />
			<input type="hidden" name="isFinish" value="Y" />-->
			<li class="aui-list-view-cell ccssoft-aui-list-view-divider">
			巡检要求
			</li>
			<li id="projectRequirement" style="min-height: 30px;padding:5px 20px;color: red">填写以下资源的实际数量</li>
			<li class="aui-list-view-cell ccssoft-aui-list-view-divider">
			记录填写
			</li>
			<li class="aui-list-view-cell aui-switch-body" style="padding: 5,10px;margin: 0px" >
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			铁塔：
			</div>
			<input id="tower_id" name="towernum" type="number" value="" class="textareaborder required" data-valid="isnull||towerCheck" data-error="铁塔数量必填，若无该资源，请填 ‘0’ !||铁塔资源数已经更改，请上传铁塔图片" style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="tower_finishcount" class="input-txt" style="color: red;display: none;"></span>
			<span id="tower_count" class="input-txt" style=" display: none;margin-left: 18px;"></span>
			<span   style="margin-left:8px;  color: red;font-size: 16px;">
			个
			</span>
			</li>
			<li class="aui-list-view-cell aui-switch-body">
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			机房：
			</div>
			<input id="room_id" name="roomnum" type="number" value="" class="textareaborder required" data-valid="isnull||roomCheck" data-error="机房数量必填，若无该资源，请填 ‘0’ !||机房资源数已经更改，请上传机房图片"  style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="room_finishcount" class="input-txt" style="color: red;display: none"></span>
			<span id="room_count" class="input-txt" style="margin-left: 18px;display: none"></span>
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
			<li class="aui-list-view-cell aui-switch-body">
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			开关电源：
			</div>
			<input id="power_id" name="powernum" type="number" value="" class="textareaborder required" data-valid="isnull||powerCheck" data-error="开关电源数量必填，若无该资源，请填 ‘0’ !||开关电源资源数已经更改，请上传开关电源图片"  style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="power_finishcount" class="input-txt" style="color: red;display: none"></span>
			<span id="power_count" class="input-txt" style="margin-left: 18px;display: none"></span>
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
			<li class="aui-list-view-cell aui-switch-body">
			<div id="tip_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			蓄电池组：
			</div>
			<input id="cell_id" name="cellnum" type="number" value="" class="textareaborder required" data-valid="isnull||cellCheck" data-error="蓄电池组数量必填，若无该资源，请填 ‘0’ !||蓄电池组资源数已经更改，请上传蓄电池组图片"  style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="cell_finishcount" class="input-txt" style="color: red;display: none"></span>
			<span id="cell_count" class="input-txt" style="margin-left: 18px;display: none"></span>
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
			<li class="aui-list-view-cell aui-switch-body">
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			交流配电箱：
			</div>
			<input id="dism_id" name="distriboxnum" type="number" value="" class="textareaborder required" data-valid="isnull||disCheck" data-error="交流配电箱数量必填，若无该资源，请填 ‘0’ !||交流配电箱资源数已经更改，请上传交流配电箱图片"  style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="dism_finishcount" class="input-txt" style="color: red;display: none"></span>
			<span id="dism_count" class="input-txt" style="margin-left: 18px;display: none"></span>
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
			<li class="aui-list-view-cell aui-switch-body">
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			空调：
			</div>
			<input id="air_id" name="airnum" type="number" value="" class="textareaborder required" data-valid="isnull||airCheck" data-error="空调数量必填，若无该资源，请填 ‘0’ !||空调资源数已经更改，请上传空调图片"  style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="air_finishcount" class="input-txt" style="color: red;display: none"></span>
			<span id="air_count" class="input-txt" style="margin-left: 18px;display: none"></span>
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
			<li class="aui-list-view-cell aui-switch-body">
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 40%;text-align: right;">
			动环监控设备：
			</div>
			<input id="mon_id" name="monitornum" type="number" value="" class="textareaborder required" data-valid="isnull||monitorCheck" data-error="动环监控设备数量必填，若无该资源，请填 ‘0’ !||动环监控设备资源数已经更改，请上传动环监控设备图片"  style="width:50%;margin: 0px;padding: 0px 15px;" >
			<span id="mon_finishcount" class="input-txt" style="color: red;display: none"></span>
			<span id="mon_count" class="input-txt" style="margin-left: 18px;display: none"></span>
			<span style="margin-left: 8px;color: red;">
			个
			</span>
			</li>
			<ul id="list-addres"></ul>
			<li id="other_id" class="aui-list-view-cell aui-switch-body">
			<span style="width: 100% ;font-weight: bold">其它设备</span>
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 30%;text-align: right;">
			类型：
			</div>
			<input id="type_id"  type="text" value="" class="textareaborder" style="width:45%;margin: 0px;" >
			<div id="tips_id" class="aui-switch-title aui-flex-middle" style="width: 30%;margin-top: 10px;text-align: right;">
			数量：
			</div>
			<input id="num_id"  type="number" value="" class="textareaborder" style="width:45%;margin: 10px 0px;padding: 0px 15px;" >
			<span class="curStatus" style="margin-left:5px;font-size: 14px;" onclick="addRes();">添加</span>
			</li>
			<li class="aui-list-view-cell ccssoft-aui-list-view-divider">
			图片列表
			</li>
			<li class="aui-list-view-cell" data-win="list-image"  >
			<img id="add" src="../../image/icons/png/icon_addpic_focused.png" width="50" height="50" style="float: left;" onclick="addPic()"/>
			</li>
			<!--<input type="file" capture="camera" accept="image/*" id="cameraInput" name="cameraInput">
			<input accept="image/*" type="file">-->
		</script>
		<!--图片模板-->
		<!--<li class="aui-list-view-cell aui-img">
		<img class="aui-img-object aui-pull-left" src="../image/demo2.png">
		<div class="aui-img-body">
		图文列表
		<p>图文列表缩略图在左边的样式，默认大小为80PX，文字介绍内容可以为一行也可以为两行，超出部分自动省略</p>
		</div>
		</li>-->
		<!--图片模板-->
		<script id="img-template" type="text/html">
			<li imgpath="{{=it.imgpath}}" class="aui-list-view-cell aui-img aui-flex-col">
			<div class=" aui-flex-item-2">
			<img class="aui-img-object aui-pull-left" src="{{=it.imgpath}}" onclick="imageUtil.show('{{=it.imgpath}}');">
			</div>
			<div class="aui-pull-left aui-flex-item-10">
			{{=(it.phototime!=null && it.phototime!= 'null')?it.phototime:''}}
			{{?typeof(it.isDel) == 'undefined' || it.isDel}}
			<span class="curStatus" style="float:right;right:10px;width:24px; font-size: 14px;margin-top: 2px;" onclick="removeImg('{{=it.imgpath}}');">X</span>
			{{?}}
			<p class='aui-ellipsis-1'>
			经纬度:{{=it.lon}},{{=it.lat}}
			</p>
			<p >
			地址:{{=it.photoaddress}}
			</p>
			<p >
			资源类型:{{=it.restype}}
			</p>
			</div>
			<!--{{?typeof(it.isDel) == 'undefined' || it.isDel}}
			<div class=" aui-flex-item-2 aui-flex-row aui-flex-middle aui-flex-center" >
			<button class="aui-btn aui-btn-danger" onclick="removeImg('{{=it.imgpath}}');">X</button>
			</div>
			{{?}}-->
			</li>
		</script>
	</body>
	<!-- third -->
	<script src="../../script/jquery-1.11.3.min.js"></script>
	<script src="../../script/template-native.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/aui.js"></script>
	<script type="text/javascript" src="../../script/doT.min.js"></script>
	<script src="../../script/GPS.js"></script>
	<script src="../../script/debug.js"></script>
	<script src='../../script/constant.js'></script>
	<script type="text/javascript" src="../../script/config.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/navigate.js"></script>
	<script type="text/javascript" src="../../script/client.api.js"></script>
	<script type="text/javascript" src="../../script/xunjian_db.js"></script>
	<script type="text/javascript" src="../../script/easydialog/easydialog.js"></script>
	<script type="text/javascript" src="../../script/utils/ImageUtil.js"></script>
	<script type="text/javascript" src="../../script/jquery-validate.js"></script>
	<script type="text/javascript" src="../../script/utils/FormUtil.js"></script>
	<script>
		var taskid, stationname;
		var imageUtil;
		var user;
		var ischecked;
		var model;
		var taskstate;
		var list = [];
		var map = null;
		var comList = new Array();
		var tempList = new Array();
		var modelType = $api.getStorage("modelType");
		var lastLocation;
		var submission = 'ONLY_SUBMIT_TEXT';
		var hiddenList;
		var towerpicnum = 0;
		var roompicnum = 0;
		var powerpicnum = 0;
		var cellpicnum = 0;
		var distriboxpicnum = 0;
		var airpicnum = 0;
		var monitorpicnum = 0;
		apiready = function() {
			user = $api.getStorage('user');
			lastLocation = $api.getStorage('LAST_GPS_LOCATION');
			initHeader();
			if (!debug) {
				db_init();
			}
			imageUtil.init({
				uploadFn : $client.uploadResCheckImage,
				saveFn : db_saveResPic
			});
			formUtil.init({
				submitFn : $client.saveResResult,
				btnObj : $('#submitBtn'),
				callback : function(ret, err) {
					if (ret && ret.success) {
						if (imageUtil.getImageArray().length) {
							if (submission == 'ONLY_SUBMIT_TEXT') {
								saveLocal();
							} else {
								imageUtil.upload(function(count) {
									api.execScript({
										name : 'xunjian_projectList',
										frameName : 'projectListFrm',
										script : 'refreshList();'
									});
									setTimeout(function() {
										api.closeWin();
									}, 1000);
								});
							}
						} else {
							api.toast({
								msg : '提交成功!'
							});
							api.execScript({
								name : 'xunjian_projectList',
								frameName : 'projectListFrm',
								script : 'refreshList();'
							});
							setTimeout(function() {
								api.hideProgress();
								api.closeWin();
							}, 1100);
						}
					} else {
						showToast("上传失败!");
					}
				},
				rules : {
					isnull : function(value, errorMsg, el) {
						//						var isStander = $('input[name=isStander]').is(':checked');
						//						if (!($('input[name=isStander]').is(':checked'))) {
						if (value == '') {
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},
					
					towerCheck : function(value, errorMsg, el) {
						if(value !=model.towernum&&towerpicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},

					roomCheck : function(value, errorMsg, el) {
						if(value !=model.roomnum&&roompicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},
	
					powerCheck : function(value, errorMsg, el) {
						if(value !=model.powernum&&powerpicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},
				cellCheck : function(value, errorMsg, el) {
						if(value !=model.cellnum&&cellpicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},
					
			
					disCheck : function(value, errorMsg, el) {
						if(value !=model.distriboxnum&&distriboxpicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},
			
					airCheck : function(value, errorMsg, el) {
						if(value !=model.airnum&&airpicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					},
			
					monitorCheck : function(value, errorMsg, el) {
						if(value !=model.monitornum&&monitorpicnum==0){
							if (!formUtil.getHasError()) {
								formUtil.setHasError(true);
								return errorMsg;
							}
							//							}
						}
					}
					
					
				}
			});
			//			api.toast({
			//	            msg:api.pageParam.takeid
			//          });
			taskid = api.pageParam.takeid;
			stationname = api.pageParam.stationname;
			taskstate = api.pageParam.taskstate;
			ischecked = api.pageParam.ischecked;
			loadResDetail(taskid);
			$('#overlay,#closeBtn').click(function() {
				easyDialog.close({
					container : 'easyDialogWrapper'
				});
			});
			//			renderTemp('list-view', 'parol-template', api.pageParam, false);
		};
		/**
		 *加载巡检项目详情
		 */
		function loadResDetail(taskid) {
			showMask("加载中...");
			var strList = new Array();
			comList.push('铁塔');
			comList.push('机房');
			comList.push('开关电源');
			comList.push('蓄电池组');
			comList.push('交流配电箱');
			comList.push('空调');
			comList.push('动环监控设备');
			$client.getResCheckList({
				taskid : taskid
			}, function(ret, err) {
				hideMask();
				if (ret) {
					if (ret.success) {
						model = ret.model;
						$.extend(model, api.pageParam);
						renderTemp('list-view', 'parol-template', model, false);
						var resFinishList = ret.list;
						if (ischecked == "true" || taskstate == "3") {
							if (resFinishList && resFinishList.length > 0) {
								for (var i = 0; i < resFinishList.length; i++) {
									strList.push(resFinishList[i].resource_type);
									if ("铁塔" == resFinishList[i].resource_type) {//如果等于铁塔，则调用重定位标签
										$('#tower_id').attr('disabled', true);
										//							resFinishList[i].real_num
										$('#tower_finishcount').html(resFinishList[i].real_num);
										$('#tower_count').html('(' + model.towernum + ')');
										$('#tower_finishcount').show();
										$('#tower_count').show();
									} else if ("机房" == resFinishList[i].resource_type) {
										$('#room_id').attr('disabled', true);
										$('#room_finishcount').html(resFinishList[i].real_num);
										$('#room_count').html('(' + model.roomnum + ')');
										$('#room_finishcount').show();
										$('#room_count').show();
									} else if ("开关电源" == resFinishList[i].resource_type) {
										$('#power_id').attr('disabled', true);
										$('#power_finishcount').html(resFinishList[i].real_num);
										$('#power_count').html('(' + model.powernum + ')');
										$('#power_finishcount').show();
										$('#power_count').show();
									} else if ("蓄电池组" == resFinishList[i].resource_type) {
										$('#cell_id').attr('disabled', true);
										$('#cell_finishcount').html(resFinishList[i].real_num);
										$('#cell_count').html('(' + model.cellnum + ')');
										$('#cell_finishcount').show();
										$('#cell_count').show();
									} else if ("交流配电箱" == resFinishList[i].resource_type) {
										$('#dism_id').attr('disabled', true);
										$('#dism_finishcount').html(resFinishList[i].real_num);
										$('#dism_count').html('(' + model.distriboxnum + ')');
										$('#dism_finishcount').show();
										$('#dism_count').show();
									} else if ("空调" == resFinishList[i].resource_type) {
										$('#air_id').attr('disabled', true);
										$('#air_finishcount').html(resFinishList[i].real_num);
										$('#air_count').html('(' + model.airnum + ')');
										$('#air_finishcount').show();
										$('#air_count').show();
									} else if ("动环监控设备" == resFinishList[i].resource_type) {
										$('#mon_id').attr('disabled', true);
										$('#mon_finishcount').html(resFinishList[i].real_num);
										$('#mon_count').html('(' + model.monitornum + ')');
										$('#mon_finishcount').show();
										$('#mon_count').show();
									}
									if (comList.indexOf(resFinishList[i].resource_type) == -1) {
										//							"*[name='name']
										renderTemp('list-addres', 'm-addres', resFinishList[i], true);
										$("[name='res_devname']").css('color', 'red');
										$("[name='addname_name']").css('color', 'red');
										$("[name='res_devname']").attr('disabled', true);
									}
								}
								//如果核准的列表没有改变，则赋原来的值
								if (strList.indexOf('铁塔') == -1) {
									$('#tower_id').val(model.towernum);
								}
								if (strList.indexOf('机房') == -1) {
									$('#room_id').val(model.roomnum);
								}
								if (strList.indexOf('开关电源') == -1) {
									$('#power_id').val(model.powernum);
								}
								if (strList.indexOf('蓄电池组') == -1) {
									$('#cell_id').val(model.cellnum);
								}
								if (strList.indexOf('交流配电箱') == -1) {
									$('#dism_id').val(model.distriboxnum);
								}
								if (strList.indexOf('空调') == -1) {
									$('#air_id').val(model.airnum);
								}
								if (strList.indexOf('动环监控设备') == -1) {
									$('#mon_id').val(model.monitornum);
								}
							} else {
								$('#tower_id').val(model.towernum);
								$('#cell_id').val(model.cellnum);
								$('#room_id').val(model.roomnum);
								$('#mon_id').val(model.monitornum);
								$('#power_id').val(model.powernum);
								$('#dism_id').val(model.distriboxnum);
								$('#air_id').val(model.airnum);
							}
							$('#tower_id').attr('disabled', true);
							$('#room_id').attr('disabled', true);
							$('#power_id').attr('disabled', true);
							$('#cell_id').attr('disabled', true);
							$('#dism_id').attr('disabled', true);
							$('#air_id').attr('disabled', true);
							$('#mon_id').attr('disabled', true);
							$('#other_id').hide();
							$('#add').parent().hide();
						} else {
							$('#tower_id').val(model.towernum);
							$('#cell_id').val(model.cellnum);
							$('#room_id').val(model.roomnum);
							$('#mon_id').val(model.monitornum);
							$('#power_id').val(model.powernum);
							$('#dism_id').val(model.distriboxnum);
							$('#air_id').val(model.airnum);
						}
						var imgList = ret.imgList;
						var historyUrl = imageUtil.getDownloadList();
						if (imgList && imgList.length > 0) {
							for (var i = 0, size = imgList.length; i < size; i++) {
								var imageUrl = imgList[i];
								historyUrl.push(imageUrl);
							}
							//							$('#add').parent().hide();
							$('#downloadBtn').show();
						}
					} else {
						showToast(ret.data_info);
					}
				} else {
					showToast(err.msg);
				}
			});
		}

		function saveLocal() {
			imageUtil.save(function(num) {
				var length = imageUtil.getImageArray().length;
				if (num) {
					//刷新首页的图片上传模块头标
					api.execScript({
						name : 'home_win',
						frameName : 'footer_tab_1',
						script : 'setofflineUploadCount();'
					});
					setTimeout(function() {
						//刷新单个列表项
						api.execScript({
							name : 'xunjian_projectList',
							frameName : 'projectListFrm',
							script : 'refreshList();'
						});
						api.hideProgress();
						api.closeWin();
					}, 2000);
				}
			});
		}

		function displaynum(x) {
			var num = new Number(x);
			return num.toFixed(6);
		}

		function showSelectBox() {
			renderTemp('doorDeviceList', 'doorDevice-template', tempList, false);
			easyDialog.open({
				container : 'easyDialogWrapper',
				fixed : true,
				drag : false,
			});
		}

		function closeDiv() {
			easyDialog.close({
				container : 'easyDialogWrapper'
			});
		}

		function getRes(el) {
			var restype = $(el).attr("data-name");
			easyDialog.close({
				container : 'easyDialogWrapper'
			});
			//         api.closeFrame();
			if (!lastLocation || !lastLocation.status) {
				api.toast({
					msg : '暂未定位\n无法上传照片！'
				});
				window.setTimeout(function() {
					api.closeWin();
				}, 2000);
			}
			var lon1 = displaynum(lastLocation.lon);
			var lat1 = displaynum(lastLocation.lat);
			imageUtil.add('camera', function(ret, err) {
				var imageInfo = {
					userid : user.userid,
					taskid : taskid,
					stationname : stationname,
					imgpath : ret.data,
					lon : lon1,
					lat : lat1,
					restype : restype,
					photoaddress : lastLocation.photoaddress,
					phototime : (new Date()).pattern("yyyy-MM-dd HH:mm:ss")
				};
				if ("铁塔" == restype) {
					towerpicnum += 1;
				} else if ("机房" == restype) {
					roompicnum += 1;
				} else if ("开关电源" == restype) {
					powerpicnum += 1;
				} else if ("蓄电池组" == restype) {
					cellpicnum += 1;
				} else if ("交流配电箱" == restype) {
					distriboxpicnum += 1;
				} else if ("空调" == restype) {
					airpicnum += 1;
				} else if ("动环监控设备" == restype) {
					monitorpicnum += 1;
				} else {//如果是新增的類型，改變picnum数量
					$.each(list, function(index, content) {
						if (content.type == restype) {
							content.picnum = content.picnum + 1;
						}
					});
				}
				imageUtil.getImageArray().push(imageInfo);
				showlog('添加一张待上传图片,待上传图片数组长度:' + imageUtil.getImageArray().length);
				renderTemp('list-view', 'img-template', imageInfo, true);
				$('#add').parent().insertAfter('#list-view li:last');
			});
		}

		/**
		 * 添加图片
		 */
		function addPic() {
			var towernum = $('#tower_id').val();
			var cellnum = $('#cell_id').val();
			var roomnum = $('#room_id').val();
			var monitornum = $('#mon_id').val();
			var powernum = $('#power_id').val();
			var distriboxnum = $('#dism_id').val();
			var airnum = $('#air_id').val();
			if (model.towernum != towernum && tempList.indexOf('铁塔') == -1) {
				tempList.push('铁塔');
			}
			if (model.cellnum != cellnum && tempList.indexOf('蓄电池组') == -1) {
				tempList.push('蓄电池组');
			}
			if (model.roomnum != roomnum && tempList.indexOf('机房') == -1) {
				tempList.push('机房');
			}
			if (model.monitornum != monitornum && tempList.indexOf('动环监控设备') == -1) {
				tempList.push('动环监控设备');
			}
			if (model.powernum != powernum && tempList.indexOf('开关电源') == -1) {
				tempList.push('开关电源');
			}
			if (model.distriboxnum != distriboxnum && tempList.indexOf('交流配电箱') == -1) {
				tempList.push('交流配电箱');
			}
			if (model.airnum != airnum && tempList.indexOf('空调') == -1) {
				tempList.push('空调');
			}
			if (tempList.length > 0) {
				showSelectBox();
			} else {
				api.toast({
					msg : '该记录没有资源变更，不能进行拍照'
				});
			}
		}

		function addRes() {
			var type = $('#type_id').val();
			var num = $('#num_id').val();
			if (num == '' || type == '') {
				api.toast({
					msg : '添加的类型或数量不能为空',
				});
				return;
			} else {
				if (comList.indexOf(type) == -1) {
					comList.push(type);
					tempList.push(type);
					var resInfo = {
						resource_type : type,
						real_num : num
					};
					renderTemp('list-addres', 'm-addres', resInfo, true);
					map = {
						type : type,
						num : num,
						picnum : 0
					};
					list.push(map);
					$('#type_id').val('');
					$('#num_id').val('');
				} else {
					api.toast({
						msg : '该类型已经添加',
					});
					return;
				}
			}
		}

		/*
		 * 下载图片
		 */
		function downloadPic() {
			imageUtil.download(function(imageData, ret, err) {
				if (ret) {
					if (ret.status) {
						console.log("图片路径：" + ret.url);
						var imageInfo = {
							imgpath : ret.url,
							lon : imageData.lon,
							lat : imageData.lat,
							phototime : imageData.phototime,
							photoaddress : imageData.photoaddress,
							restype :imageData.restype,
							isDel : false
						};
						imageUtil.getImageArray().push(imageInfo);
						renderTemp('list-view', 'img-template', imageInfo, true);
					} else {
						api.toast({
							msg : '加载图片失败！'
						});
					}
				} else {
					api.toast({
						msg : '缓存图片失败！'
					});
				}
			});
		}

		/**
		 *删除图片
		 */
		function removeImg(imgPath) {
			var imageArray = imageUtil.getImageArray();
			var size = imageArray.length;
			for (var i = 0; i < size; i++) {
				var data = imageArray[i];
				if (data.imgpath == imgPath) {
				
				if ("铁塔" == data.restype) {
					towerpicnum -= 1;
				} else if ("机房" == data.restype) {
					roompicnum -= 1;
				} else if ("开关电源" == data.restype) {
					powerpicnum -= 1;
				} else if ("蓄电池组" == data.restype) {
					cellpicnum -= 1;
				} else if ("交流配电箱" == data.restype) {
					distriboxpicnum -= 1;
				} else if ("空调" == data.restype) {
					airpicnum += 1;
				} else if ("动环监控设备" == data.restype) {
					monitorpicnum -= 1;
				} else {//如果是新增的類型，改變picnum数量
					$.each(list, function(index, content) {
						if (content.type == data.restype) {
							content.picnum = content.picnum -1;
						}
					});
				}
				
					imageArray.remove(i);
					break;
				}
			}
			$(event.target).parents('li').remove();
		}

		function call_upload(result) {
			var opt = {};
			opt.billtype="1"
			opt.towerpicnum = towerpicnum;
			opt.roompicnum = roompicnum;
			opt.cellpicnum = cellpicnum;
			opt.distriboxpicnum = distriboxpicnum;
			opt.airpicnum = airpicnum;
			opt.monitorpicnum = monitorpicnum;
			opt.powerpicnum = powerpicnum;
			opt.list = list;
			if (result == '提交文本和图片') {
				submission = 'BOTH_SUBMIT_TEXT_IMAGE';
				formUtil.setQueryOptions(opt);
				//				formUtil.setQueryOptions(opt);
				formUtil.submit();
			} else if (result == '仅提交文本') {
				submission = 'ONLY_SUBMIT_TEXT';
				formUtil.setQueryOptions(opt);
				//				formUtil.setQueryOptions(opt);
				formUtil.submit();
			}
		}

		function call_validate() {
			if (formUtil.validate()) {
				if(list!=null&&list.length>0){
				
				$.each(list, function(index, content) {
						if (content.type !=null&&content.picnum==0&&content.num!=0) {
							api.toast({
							msg : '新增的'+content.type+'资源，必须上传相关的图片',
							duration : 1500,
							location : 'bottom'
						});
						}else{
						select();
						}
					});
			}else{
				select();
			}
			}
		}

		/**
		 *  选择提交方式：1.提交文本和图片，2. 仅提交文本
		 */
		function select() {
			$aui.dialog({
				title : '提交确认',
				text : '是否提交资源核准信息?'
			}, function(ret) {
				if (ret.buttonIndex) {
					var optList = ['提交文本和图片', '仅提交文本'];
					var cbTarget = {
						name : api.winName,
						frameName : 'resAdd_frm',
						cbFn : 'call_upload'
					};
					$api.setStorage('optList', optList);
					$api.setStorage('cbTarget', cbTarget);
					api.openFrame({
						name : 'popup_select_frm',
						url : '../dialog/popup_select.html',
						pagePara : api.pageParam,
						bounces : false
					});
				}
				$aui.hideDialog();
			});
		}
	</script>
</html>